//
//  SplashAdM.m
//  TestDemo
//
//  Created by a on 2022/11/29.
//

#import "SplashAdM.h"
#import <LDMobileAdSDK/LDMobileAdSDK.h>

@interface SplashAdM ()<LDSplashAdDelegate>

@property (nonatomic,strong)LDSplashAd * splashAd;

@end

@implementation SplashAdM

- (instancetype)init{
    self = [super init];
    if(self){
        [self config];
    }
    return self;
}

- (void)config{
    self.autoShow = YES;
}

- (void)setupSplashAd:(UIWindow *)window{
    [LDSDKConfig setAppKey:@"f7d19924efe93778" token:@"cvvcqdnyrk"];
    self.splashAd = [[LDSplashAd alloc] initWithSlotID:@"7311842" window:window]; // u净
    self.splashAd.delegate = self;
    if (self.autoShow == YES) {
        [self.splashAd loadAndShow];
    }else{
        [self.splashAd loadAd];
    }
    if (self.autoShow == NO){
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.splashAd showAd];
        });
    }
    
}

- (void)dealloc{
    NSLog(@"SplashAdM dealloc");
}

#pragma mark -LDSplashAdDelegate
- (void)splashAdDidLoad:(id)splashAd{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
    if (self.autoShow == YES) {
        [self.splashAd showAd];
    }
}

///开屏曝光
- (void)splashAdDidExposure:(id)splashAd{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
    if (self.adHasShowed != nil) {
        self.adHasShowed();
    }
}

- (void)splashAdFail:(id)splashAd error:(NSError *)error{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
    NSLog(@"%@",error);
    if (self.adHasShowed != nil) {
        self.adHasShowed();
    }
    self.splashAd.delegate = nil;
    self.splashAd = nil;
}

- (void)splashAdClick:(id)splashAd{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
    if (self.adHasShowed != nil) {
        self.adHasShowed();
    }
}

- (void)splashAdClose:(id)splashAd{
    NSLog(@"---------%@",NSStringFromSelector(_cmd));
    if (self.adHasShowed != nil) {
        self.adHasShowed();
    }
    self.splashAd.delegate = nil;
    self.splashAd = nil;
}



@end
